package org.skywork.top.core.algorithm.num;

import java.util.Map;

/**
 * 罗马数字转整数
 */
public class no_13 {

    public int romanToInt(String s) {
        int[] symbolValues = new int[26];
        symbolValues['I' - 'A'] = 1;
        symbolValues['V' - 'A'] = 5;
        symbolValues['X' - 'A'] = 10;
        symbolValues['L' - 'A'] = 50;
        symbolValues['C' - 'A'] = 100;
        symbolValues['D' - 'A'] = 500;
        symbolValues['M' - 'A'] = 1000;

        int res = 0;
        for(int i = 0; i < s.length(); i++){
            int val = symbolValues[s.charAt(i) - 'A'];
            if(i < s.length() - 1 &&  val < symbolValues[s.charAt(i + 1) - 'A']){
                res -= val;
            }else{
                res += val;
            }
        }
        return res;
    }

    public boolean checkStr(String s, String[] strs, Map<String, Integer> map) {
        for (String str : strs) {
            if (map.get(str) == null) {
                return true;
            }
        }
        return s.contains("IL") || s.contains("IM");
    }

}
